fix: limit decompressed request body size to prevent memory exhaustion#1091
Open
vnykmshr wants to merge 2 commits intonode-formidable:masterfrom
Open
fix: limit decompressed request body size to prevent memory exhaustion#1091vnykmshr wants to merge 2 commits intonode-formidable:masterfrom
vnykmshr wants to merge 2 commits intonode-formidable:masterfrom
Conversation
JSON and urlencoded parsers buffer the entire decompressed body with no size check. A gzip-compressed request can force unbounded memory allocation (50KB compressed, 200MB+ RSS with default settings). Add bytesReceived check in write() against maxTotalFileSize. Multipart was already protected via _handlePart; this closes the gap for JSON and urlencoded paths. Refs node-formidable#1063
Member
|
will check out when i get up. thanks. we'll also land i'm planning the migration to monorepo setup |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The JSON and querystring parsers (
this.chunks[],this.buffer) have no size check on the decompressed body. A 50KB gzip request decompresses to ~50MB -maxTotalFileSizeonly fires in the multipart path.This adds a
bytesReceivedcheck inwrite(). When total decompressed bytes exceedmaxTotalFileSize, parsing stops with a 413.My earlier suggestion in #1063 about
maxOutputLengthwas wrong - that option only applies to sync zlib (gunzipSync), not streaming transforms.Refs #1063 (remaining item after #1069)